import qualified Data.ByteString.Char8 as B

nearestMultipleOf :: Integral a => a -> a -> a
nearestMultipleOf n k = if mod n k == 0 then n else nearestMultipleOf (n-1) k

sumMultiplesOf :: Integral a => a -> a -> a
sumMultiplesOf n k = foldl (+) 0 [k,k*2..nearest]
    where nearest = nearestMultipleOf n k
    
solution :: Integral a => a -> a
solution n = s03 + s05 - s15
    where s03 = sumMultiplesOf n 3
          s05 = sumMultiplesOf n 5
          s15 = sumMultiplesOf n 15
          
main = do
    c <- B.readFile "C:\\Users\\JeanCarlo\\SkyDrive\\Haskell\\HackerRank\\Contests\\Project Euler\\001 - Multiples of 3 and 5\\input01.txt"
    let ns = tail $ B.lines c
    B.putStr $ B.unlines ns -- $ map (solution' . B.readInt) ns       